#ifndef _UTIL_H_
#define _UTIL_H_

#include <variant>

namespace SEngine
{
    template<size_t T, size_t... Ts>
    constexpr inline size_t AllSize() {
        if constexpr (sizeof...(Ts) != 0) {
            return T + AllSize<Ts...>();
        } else {
            return T;
        }
        return 0;
    }

    template<size_t idx = 0, typename T, typename F>
    void VariantGet(T & v, F && fn) {
        if (idx == v.index()) {
            fn(std::get<idx>(v));
        }
        if constexpr (idx + 1 < std::variant_size_v<std::decay_t<T>>) {
            VariantGet<idx + 1>(v, std::forward<F>(fn));
        }
    }


    // template<typename T>
    // struct has_member_s{
    //     template <typename _T>
    //     static auto check(_T)->typename std::decay<decltype(_T::s)>::type;
    //     static void check(...);
    //     using type=decltype(check(std::declval<T>()));
    //     enum{value=!std::is_void<type>::value};
    // };

    void glCheckError_(const char *file, int line);
    void glClearError_();

    #define glCheckError() glCheckError_(__FILE__, __LINE__) 
    #define glCall(fn) { glClearError_(); fn; glCheckError(); }
} // namespace SEngine


#endif